﻿/* SystemCommands.cs
 *
 * Shuriken is the legal property of its developers. Please refer to the
 * COPYRIGHT file distributed with this
 * source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

using System;
using Shuriken.Base;
using System.Collections.Generic;

namespace SystemCommands
{

    public class LockCommand : ISubject
    {
        #region ISubject Members

        public List<IAction> GetListOfActions()
        {
            List<IAction> actions = new List<IAction>();
            actions.Add(new GeneralAction("Run", "Run Command", string.Empty, true, false,new ActionExecuteDelegate(ExecuteAction), this.GetType()));
            return actions; 
        }

        #endregion

        #region IObject Members

        public string Name
        {
            get { return "Lock"; }
        }

        public string Description
        {
            get { return "Lock this computer"; }
        }

        public string Icon
        {
            get
            {
                return string.Empty;
            }
            set
            {
                
            }
        }

        #endregion

        public void ExecuteAction(ISubject subject)
        {
            SystemCommandsHelper.LockComputer();
        }        
    }

    public class SleepCommand : ISubject
    {
        #region ISubject Members

        public List<IAction> GetListOfActions()
        {
            List<IAction> actions = new List<IAction>();
            actions.Add(new GeneralAction("Run", "Run Command", string.Empty, true, false, new ActionExecuteDelegate(ExecuteAction), this.GetType()));
            return actions;
        }

        #endregion

        #region IObject Members

        public string Name
        {
            get { return "Sleep"; }
        }

        public string Description
        {
            get { return "Sends this computer to sleep."; }
        }

        public string Icon
        {
            get
            {
                return string.Empty;
            }
            set
            {

            }
        }

        #endregion

        public void ExecuteAction(ISubject subject)
        {
            SystemCommandsHelper.Sleep();
        }
    }

    public class RestartCommand : ISubject
    {
        #region ISubject Members

        public List<IAction> GetListOfActions()
        {
            List<IAction> actions = new List<IAction>();
            actions.Add(new GeneralAction("Run", "Run Command", string.Empty, true, false, new ActionExecuteDelegate(ExecuteAction), this.GetType()));
            return actions;
        }

        #endregion

        #region IObject Members

        public string Name
        {
            get { return "Restart"; }
        }

        public string Description
        {
            get { return "Restart Computer"; }
        }

        public string Icon
        {
            get
            {
                return string.Empty;
            }
            set
            {

            }
        }

        #endregion

        public void ExecuteAction(ISubject subject)
        {
            SystemCommandsHelper.Restart();
        }
    }

    public class ForceRestartCommand : ISubject
    {
        #region ISubject Members

        public List<IAction> GetListOfActions()
        {
            List<IAction> actions = new List<IAction>();
            actions.Add(new GeneralAction("Run", "Run Command", string.Empty, true, false, new ActionExecuteDelegate(ExecuteAction), this.GetType()));
            return actions;
        }

        #endregion

        #region IObject Members

        public string Name
        {
            get { return "Force Restart"; }
        }

        public string Description
        {
            get { return "Force Restart Computer"; }
        }

        public string Icon
        {
            get
            {
                return string.Empty;
            }
            set
            {

            }
        }

        #endregion

        public void ExecuteAction(ISubject subject)
        {
            SystemCommandsHelper.ForceRestart();
        }
    }

    public class ShutdownCommand : ISubject
    {
        #region ISubject Members

        public List<IAction> GetListOfActions()
        {
            List<IAction> actions = new List<IAction>();
            actions.Add(new GeneralAction("Shutdown", "Run Command", string.Empty, true, false, new ActionExecuteDelegate(ExecuteCommand), this.GetType()));
            return actions;
        }

        #endregion

        #region IObject Members

        public string Name
        {
            get { return "Shut Down"; }
        }

        public string Description
        {
            get { return "Shut down the computer"; }
        }

        public string Icon
        {
            get
            {
                return string.Empty;
            }
            set
            {

            }
        }

        #endregion

        public void ExecuteCommand(ISubject subject)
        {
            SystemCommandsHelper.Shutdown();
        }
    }

    public class ForceShutdownCommand : ISubject
    {
        #region ISubject Members

        public List<IAction> GetListOfActions()
        {
            List<IAction> actions = new List<IAction>();
            actions.Add(new GeneralAction("Run", "Run Command", string.Empty, true, false, new ActionExecuteDelegate(ExecuteCommand), this.GetType()));
            return actions;
        }

        #endregion

        #region IObject Members

        public string Name
        {
            get { return "Force Shut Down"; }
        }

        public string Description
        {
            get { return "Shut down the computer"; }
        }

        public string Icon
        {
            get
            {
                return string.Empty;
            }
            set
            {

            }
        }

        #endregion

        public void ExecuteCommand(ISubject subject)
        {
            SystemCommandsHelper.ForceShutdown();
        }
    }

    public class LogOffComputerCommand : ISubject
    {
        #region ISubject Members

        public List<IAction> GetListOfActions()
        {
            List<IAction> actions = new List<IAction>();
            GeneralAction run = new GeneralAction("Run", "Run Command", string.Empty, true, false, new ActionExecuteDelegate(delegate(ISubject target) { SystemCommandsHelper.LogOff(); }), this.GetType());
            actions.Add(run);

            return actions;
        }

        #endregion

        #region IObject Members

        public string Name
        {
            get { return "Log Off"; }
        }

        public string Description
        {
            get { return ""; }
        }

        public string Icon
        {
            get
            {
                return string.Empty; ;
            }
            set
            {
            }
        }

        #endregion

    }

    public class SystemCommandsScanner : IScanner
    {
        #region IScanner Members

        public List<ISubject> Items
        {
            get 
            {   List<ISubject> commands = new List<ISubject>();
                commands.Add(new LockCommand());
                commands.Add(new SleepCommand());
                commands.Add(new RestartCommand());
                commands.Add(new ForceRestartCommand());
                commands.Add(new ShutdownCommand());
                commands.Add(new ForceShutdownCommand());
                commands.Add(new LogOffComputerCommand());

                return commands; 
            }
        }

        public void Update()
        {
        }

        #endregion

        #region IObject Members

        public string Name
        {
            get { return "System Commands"; }
        }

        public string Description
        {
            get { return "Implements various system commands"; }
        }

        public string Icon
        {
            get
            {
                return string.Empty;
            }
            set
            {
                
            }
        }

        #endregion
    }
}
